<template>
	<view>
		<view class="content" v-if="dataList.length < 1">
			<u-empty text="所谓伊喵，干饭第一" mode="list"></u-empty>
		</view>
		<view v-else>
			<view v-for="(item,index) in dataList" :key="item.id">
				<view class="item" @tap="seeme(item,index)">
					<view style="width: 100%; height: 83%; overflow: hidden;border-radius: 25rpx 25rpx 0% 0%">
						<u-image style=" width: 100%; " :src="item.sysFileInfos[0].fileUrl" mode="widthFix"
							:lazy-load="true"><u-loading slot="loading"></u-loading></u-image>
					</view>
					<view style="display: flex; justify-content: space-between;align-items: center; padding:2% 4%;">
						<view style="width: 40%;display: flex;align-items: center;">
							<u-avatar :src="item.avatar" size="60" @click="pageToMine()"></u-avatar>
							<text style="margin-left: 1%;">{{item.nickName}}</text>
						</view>
						<view style="width: 60%;display: flex;justify-content: flex-end;">
							{{formatTime(item.createTime,'{y}-{m}-{d}')}}
							<text style="margin: 0 5rpx;">|</text>
							<u-icon name="eye-fill" size="34"></u-icon>
							<text style="margin-left: 5rpx;">{{item.review}}</text>
						</view>
					</view>
				</view>
			</view>
			<u-loadmore status="nomore" />
		</view>
	</view>
</template>

<script>
	import {
		getEatingList,
		updateEating
	} from '@/api/bot/eating'
	import config from '@/config'
	export default {
		name: "Eating",
		props: ["query"],
		data() {
			return {
				image: 'https://lintingfeng.top:8989/profile/avatar/2023/12/15/TDhk8nHEiitcd694bdb046d015697db6c5b3257a3281_20231215183856A003.png',
				dataList: [],
				baseUrl: config.baseUrl,
			};
		},
		mounted() {
			this.getEatingList()
		},
		watch: {
			query(newValue) {
				if (newValue.pageNum == 1) {
					this.dataList = []
				}
				this.getEatingList()
			}
		},
		methods: {
			seeme(obj) {
				this.$emit('openExtend', obj)
				obj.review = obj.review + 1
				this.updateEating(obj)
			},
			getEatingList() {
				uni.showLoading({
					title: "加载中..."
				})
				uni.getStorage({
					key: 'groupIdByIndex',
					success: (res) => {
						let data = JSON.parse(res.data);
						let groupId = data.id;
						let query = {
							...this.query,
							groupId: groupId
						}
						this.getList(query)
					}
				});
			},
			getList(query) {
				getEatingList(query).then(res => {
					res.rows.forEach(element => {
						element.avatar = this.baseUrl + element.avatar
						element.createTime = new Date(element.createTime).getTime()
					})
					this.dataList = this.dataList.concat(res.rows);
					uni.hideLoading()
				})
			},
			updateEating(obj) {
				updateEating(obj).then(res => {
					if (res.code == 200) {
						console.log('浏览量增加');
					} else {
						console.log('请求失败');
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		flex: 1;
		display: flex;
		justify-content: center;
		align-items: center;
		margin-top: 10%;
	}

	.item {
		height: 600rpx;
		border-radius: 20rpx;
		box-shadow: 0px 10px 10px 5px #0000001A;
		background-color: white;
		margin: 10rpx 0;
	}
</style>